package cn.sll.user.controller;

import cn.sll.base.util.AjaxResult;
import cn.sll.user.dto.AccountDto;
import cn.sll.user.dto.BinderDto;
import cn.sll.user.dto.WecathDto;
import cn.sll.user.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid AccountDto dto){
        HashMap<String, Object> account = loginService.account(dto);
        return new AjaxResult().me().success(account);
    }

    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WecathDto dto){
        return loginService.wechat(dto);
    }

    @PostMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody @Valid BinderDto dto){
        return loginService.binder(dto);
    }

}
